using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.WindowsMobile.PocketOutlook;

namespace PocketGCal
{
    /// <summary>
    /// Contains outlook appointments
    /// </summary>
    class OutlookAppointments : List<Appointment>
    {
        /// <summary>
        /// Create collection of appointments with our without google id set
        /// </summary>
        /// <param name="apps">Appointment collection from outlook session</param>
        /// <param name="Google">Include only appointments with google ID set (otherwise only those without)</param>
        public OutlookAppointments(AppointmentCollection apps, bool Google)
        {
            foreach (Appointment oApp in apps)
            {
                if (oApp.Properties.Contains("GCalID") && Google)
                {
                    this.Add(oApp);
                }
                else if ((!oApp.Properties.Contains("GCalID") || oApp.Properties["GCalID"]==null) && !Google)
                {
                    this.Add(oApp);
                }
            }
        }
        /// <summary>
        /// If contains appointment with a google ID
        /// </summary>
        /// <param name="id">Google ID to look for</param>
        /// <returns></returns>
        public bool Contains(string id)
        {
            return GetById(id) == null ? false : true;
        }

        /// <summary>
        /// Get by google ID
        /// </summary>
        /// <param name="id">Google ID to look for</param>
        /// <returns></returns>
        public Appointment GetById(string id)
        {
            foreach (Appointment ap in this)
            {
                if (ap.Properties.Contains("GCalID") && ap.Properties["GCalID"]!=null && ap.Properties["GCalID"].ToString() == id)
                {
                    return ap;
                }
            }
            return null;
        }
        
    }
}
